package com.jier.common.interceptor;

import com.jier.entities.User;
import com.google.gson.Gson;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by jie_r on 2016/9/22.
 */
public class AdminInterceptor extends HandlerInterceptorAdapter {
    private static final String LOGIN = "/view/login.jsp";

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session = request.getSession();
        if (session == null) {
            response.sendRedirect(LOGIN);
            return false;
        }
        User user = (User) session.getAttribute("currentUser");
        if (user == null) {
            response.sendRedirect(LOGIN);
            return false;
        }
        return true;
    }
}
